/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.blogborea.client;

import com.google.gwt.user.client.WindowResizeListener;
import com.google.gwt.user.client.WindowResizeListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 *
 * @author michael
 */
public class Application extends Composite implements WindowResizeListener {
    final static String DEFAULT_STYLE_NAME = "Blogborea";

    FlexTable topPanel = null;
    HorizontalPanel linksPanel = null;


    public Application() {
        // Setup the main layout widget
        FlowPanel layout = new FlowPanel();
        initWidget(layout);

        // Setup the top panel with the title and links
        createTopPanel();
        layout.add(topPanel);
    }

    private void createTopPanel() {
        topPanel = new FlexTable();
        topPanel.setCellPadding(0);
        topPanel.setCellSpacing(0);
        topPanel.setStyleName(DEFAULT_STYLE_NAME + "-top");
        FlexCellFormatter formatter = topPanel.getFlexCellFormatter();

        // Setup the links cell
        linksPanel = new HorizontalPanel();
        topPanel.setWidget(0, 0, linksPanel);
        formatter.setStyleName(0, 0, DEFAULT_STYLE_NAME + "-links");

        // Align the content to the top
        topPanel.getRowFormatter().setVerticalAlign(0,
                HasVerticalAlignment.ALIGN_TOP);
    }

    void addLink(Widget link) {
        if (linksPanel.getWidgetCount() > 0) {
            linksPanel.add(new HTML("&nbsp;|&nbsp;"));
        }
        linksPanel.add(link);
    }

    public void onWindowResized(int width, int height) {
        //TODO change everything on window resize
    }

}
